<!doctype html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>智能水表抄表系统 - 历史记录</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="/static/styles/main.css">
</head>

<body>
    <header class="header">
        <h1><i class="fas fa-tint"></i> 智能水表抄表系统</h1>
    </header>

    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
        <div class="container">
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/"><i class="fas fa-home"></i> 首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="/history"><i class="fas fa-history"></i> 历史记录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/bills"><i class="fas fa-file-invoice-dollar"></i> 账单管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/anomalies"><i class="fas fa-exclamation-triangle"></i> 异常记录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/water_plans"><i class="fas fa-project-diagram"></i> 水务规划</a>
                    </li>
                    {% if user and user.role == "admin" %}
                    <li class="nav-item">
                        <a class="nav-link" href="/admin"><i class="fas fa-user-shield"></i> 管理控制台</a>
                    </li>
                    {% endif %}
                </ul>
                <div class="navbar-nav">
                    <span class="nav-item nav-link">
                        <i class="fas fa-user"></i> {{ user.username }}
                    </span>
                    <a class="nav-link" href="/logout"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
                </div>
            </div>
        </div>
    </nav>

    <div class="container py-4">
        <div class="row">
            <div class="col-lg-10 mx-auto">
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <div>
                            <i class="fas fa-history"></i> 历史抄表记录
                            {% if user.role == 'admin' %}
                            <span class="badge bg-info">管理员查看所有记录</span>
                            {% else %}
                            <span class="badge bg-primary">个人记录</span>
                            {% endif %}
                        </div>
                        <a href="/" class="btn btn-sm btn-custom-secondary">
                            <i class="fas fa-home"></i> 返回首页
                        </a>
                    </div>
                    <div class="card-body">
                        {% if readings and readings|length > 0 %}
                        <div class="table-container">
                            <table class="custom-table">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>水表编号</th>
                                        <th>水表读数</th>
                                        <th>抄表时间</th>
                                        <th>图片</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for reading in readings %}
                                    <tr>
                                        <td>{{ reading.id }}</td>
                                        <td>{{ reading.meter_code }}</td>
                                        <td>{{ reading.reading_value }}</td>
                                        <td>{{ reading.timestamp }}</td>
                                        <td>
                                            <a href="{{ reading.image_path }}" target="_blank">
                                                <img src="{{ reading.image_path }}" alt="水表图片" class="thumbnail">
                                            </a>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                        {% else %}
                        <div class="empty-state">
                            <i class="fas fa-inbox"></i>
                            <p>暂无抄表记录</p>
                        </div>
                        {% endif %}
                    </div>
                </div>

                <!-- 数据统计卡片 -->
                {% if readings and readings|length > 0 %}
                <div class="card mt-4">
                    <div class="card-header">
                        <i class="fas fa-chart-bar"></i> 抄表数据统计
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="card bg-light">
                                    <div class="card-body text-center">
                                        <h5 class="card-title"><i class="fas fa-list-ol text-primary"></i> 总记录数</h5>
                                        <p class="card-text fs-2">{{ readings|length }}</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card bg-light">
                                    <div class="card-body text-center">
                                        <h5 class="card-title"><i class="fas fa-calendar-alt text-success"></i> 最新抄表日期</h5>
                                        <p class="card-text">{{ readings[0].timestamp if readings|length > 0 else '无' }}</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card bg-light">
                                    <div class="card-body text-center">
                                        <h5 class="card-title"><i class="fas fa-water text-info"></i> 最新读数</h5>
                                        <p class="card-text">{{ readings[0].reading_value if readings|length > 0 else '无' }}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                {% endif %}
            </div>
        </div>
    </div>

    <footer class="footer">
        <div class="container">
            <p>&copy; 2023 智能水表抄表系统 | 提供水表读数和编码识别</p>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
        crossorigin="anonymous"></script>
</body>

</html> 